<template>
  <com-drag-over @comDrop="comDrop">
    <div
      class="_cart _m-r-10 _backdrop _m-b-10 _flex _flex-a-stretch _flex-start _over-hidden"
    >
      <div class="_m-r-5 _text-dir-y _text-a-c _background-2">
        {{ blockName }}
      </div>
      <div class="_flex _flex-wrap _flex-start _flex-space _p5">
        <template v-for="app in currApps" :key="app.name">
          <com-drag :data="app">
            <app
              :text="app.name"
              :imgSrc="app.icon"
              :comData="app.data"
              @dblclick="$emit('openWin', app)"
            ></app>
          </com-drag>
        </template>
      </div>
    </div>
  </com-drag-over>
</template>

<script>
import ComDragOver from "@/components/com-drag/com-drag-over.vue";
import ComDrag from "@/components/com-drag/com-drag.vue";
import toolAction from "@/tool/http/tool-action";
import App from "./app.vue";

let actionAccountMenu = toolAction.init("account_menu");

export default {
  components: { App, ComDrag, ComDragOver },
  props: {
    pid: {
      type: [String, Number],
      default: "0",
    },
    apps: {
      type: Array,
      default: () => [],
    },
    blockName: {
      type: String,
      default: "默认",
    },
  },
  computed: {
    currApps() {
      return this.apps.filter(
        (item) =>
          item.data.pid == this.pid &&
          item.data.com_resource.enum_res_type == "APP"
      );
    },
  },
  methods: {
    comDrop({ data }) {
      actionAccountMenu.sync({ id: data.data.id, pid: this.pid }).then(() => {
        this.$comStore.login.refreshRes();
      });
    },
  },
};
</script>

<style></style>
